package com.atguigu.gmall.gmalllogger;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author lzc
 * @Date 2022/4/13 14:31
 */
@RestController
@Slf4j
public class LoggerController {
    
    @RequestMapping("/applog")
    public String logger(@RequestParam("param") String param){
        // 1. 数据写入到磁盘
        saveToDisk(param);
        // 2. 数据发送到kafka 重要
        sendToKafka(param);
        
        return "ok";
    }
    
    @Autowired
    KafkaTemplate<String, String> kafka;
    private void sendToKafka(String param) {
        kafka.send("ods_log", param);
    }
    
    private void saveToDisk(String param) {
        log.info(param);
    }
    
}
